package com.foxire.demo;

// 智能家居控制类  单例类
public class SmartHomeControl {
    private static final SmartHomeControl smartHomeControl = new SmartHomeControl();
    private SmartHomeControl() {}
    public static SmartHomeControl getInstance() {
        return smartHomeControl;
    }
    // 多态
    public void control(JD jd) {
        System.out.println("控制：" + jd.getName() + "目前状态是：" + (jd.isStatus() ? "开" : "关"));
        System.out.println("请操作");
        jd.press();
        System.out.println(jd.getName() + "目前状态是：" + (jd.isStatus() ? "开" : "关"));
    }

    public void show(JD[] jds) {
        for (int i = 0; i < jds.length; i++) {
            JD jd = jds[i];
            System.out.println((i + 1) + "--" + jd.getName() + "目前状态是：" + (jd.isStatus() ? "开" : "关"));
        }
    }
}
